package com.sansecy.monitor.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.DisplayMetrics;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.sansecy.monitor.R;
import com.sansecy.monitor.see.ActivityManger;
import com.sansecy.monitor.utils.Utils;

/**
 * @Description TODO
 * @Date 2019-08-04 21:48
 * @Created by caoyu
 */
public class DeviceInfoDialog extends Dialog {

    public DeviceInfoDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Activity activity = ActivityManger.getTopActivity();
        setContentView(R.layout.dialog_device_info);
        TextView heightWidth = findViewById(R.id.height_width);
        TextView decorHeightWidth = findViewById(R.id.decor_height_width);
        TextView statusBarHeight = findViewById(R.id.status_bar_height);
        TextView navigationBarHeight = findViewById(R.id.navigation_bar_height);
        TextView density = findViewById(R.id.density);
        TextView scaledDensity = findViewById(R.id.scaled_density);
        TextView densityDpi = findViewById(R.id.density_dpi);
        TextView diagonalLength = findViewById(R.id.diagonal_length);
        diagonalLength.setText(String.valueOf(Utils.getScreenInch(activity)));
        heightWidth.setText(String.format("%sx%s", Utils.getScreenWidth(getContext()), Utils.getScreenHeight(getContext())));
        decorHeightWidth.setText(String.format("%sx%s", Utils.getDecorViewWidth(activity), Utils.getDecorViewHeight(activity)));
        statusBarHeight.setText(String.valueOf(Utils.getStatusBarHeight(getContext())));
        navigationBarHeight.setText(String.valueOf(Utils.getNavigationBarHeight(getContext())));
        density.setText(String.valueOf(Utils.getScreenDensity(getContext())));
        scaledDensity.setText(String.valueOf(Utils.getScreenScaledDensity(getContext())));
        densityDpi.setText(String.valueOf(Utils.getScreenDensityDpi(getContext())));
    }

    @Override
    protected void onStart() {
        super.onStart();
        Window win = getWindow();
        DisplayMetrics dm = new DisplayMetrics();
        // 一定要设置Background，如果不设置，window属性设置无效
        assert win != null;
//        win.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        win.getWindowManager().getDefaultDisplay().getMetrics(dm);
        WindowManager.LayoutParams params = win.getAttributes();
        //设置dialog高度
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        //设置dialog宽度
        params.width = (int) (Utils.getScreenWidth(getContext()) * 0.85);
        win.setAttributes(params);
    }
}
